package org.four.user.controller;

import org.four.common.model.*;
import org.four.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    //投递简历
    @RequestMapping("addli")
    public void addli(@RequestBody ToudiBean toudiBean){
        userService.addli(toudiBean);
    }

    //测试
    @RequestMapping("findTree")
    public List<NavBean> findTree(){
        return userService.findTree();
    }

    //查询一条
    @RequestMapping("testAccount")
    public UserBean testAccount(String account){
        return userService.testAccount(account);
    }

    //注册
    @RequestMapping("saveUser")
    public void saveUser(@RequestBody UserBean userBean){
        userService.saveUser(userBean);
    }

    //登陆
    @RequestMapping("login")
    public Map login(@RequestBody UserBean userBean,HttpServletRequest request){
        return userService.login(userBean,request);
    }

    //查询简历
    @RequestMapping("queryProduct")
    public LayuiPage queryProduct(int limit , int page,Integer id){
        return userService.queryProduct(limit,page,id);
    }

    //新增简历
    @RequestMapping("addUser")
    public void addUser(@RequestBody ZhiweiBean zhiweiBean){
        userService.addUser(zhiweiBean);
    }

    //修改简历
    @RequestMapping("upda")
    public void upda(@RequestBody ProductBean productBean){
        userService.upda(productBean);
    }

    //简历回显
    @RequestMapping("findProductInfo")
    public ProductBean findProductInfo(Integer id){
        return userService.findProductInfo(id);
    }

    //查询投递
    @RequestMapping("toudi")
    public LayuiPage toudi(int limit , int page,Integer id){
        final LayuiPage toudi = userService.toudi(limit, page, id);
        return toudi;
    }

    /**
     * 个人中心分页查询商品
     */
    @RequestMapping("queryProductcjq")
    public LayuiPage queryProductcjq(Integer id){
        LayuiPage layuiPage = userService.queryProductcjq(id);
        return layuiPage;
    }

    /**
     * 收藏分页查询商品
     */
    @RequestMapping("queryzhiwei")
    public LayuiPage queryzhiwei(int limit , int page){
        LayuiPage layuiPage = userService.queryzhiwei(limit, page);
        return layuiPage;
    }

    /**
     * 订阅分页查询商品
     */
    @RequestMapping("querydingyue")
    public LayuiPage querydingyue(int limit , int page,@RequestBody ZhiweiBean zhiweiBean){
        LayuiPage layuiPage = userService.querydingyue(limit, page,zhiweiBean);
        return layuiPage;
    }

    //订阅回显
    @RequestMapping("findyue")
    @ResponseBody
    public ZhiweiBean findyue(Integer id){
        ZhiweiBean productInfo = userService.findyue(id);
        return productInfo;
    }

    /**
     * 删除收藏
     * */
    @RequestMapping("delcjq")
    public void delcjq(Integer[] id){
        userService.delcjq(id);
    }

    /**
     * 删除订阅
     * */
    @RequestMapping("del2")
    public void del2(Integer[] id){
        userService.del2(id);
    }

    /**
     * 新增订阅
     * */
    @RequestMapping("addProductcjq")
    public void addProductcjq(@RequestBody ZhiweiBean zhiweiBean){
        userService.addProductcjq(zhiweiBean);
    }

    /**
     * 修改订阅
     * */
    @RequestMapping("updacjq")
    public void updacjq(@RequestBody ZhiweiBean zhiweiBean){
        userService.updacjq(zhiweiBean);
    }

    /**
     * 跳转
     * */
    @RequestMapping("jiekou")
    @ResponseBody
    public List<ZhaoPinBean> findProductListImg(){
        return userService.findProductListImg();
    }

    /**
     * 根据id查询商品详情
     * */
    @RequestMapping("queryProductById")
    @ResponseBody
    public List<Map> queryProductById(Integer id){

        return userService.queryProductById(id);
    }

    /**
     *账号设置查询
     */
    @RequestMapping("haolist")
    public LayuiPage haolist(int limit , int page){
        LayuiPage layuiPage = userService.haolist(limit, page);
        return layuiPage;
    }

    //账号设置
    @RequestMapping("zhanggai")
    public void zhanggai(@RequestBody UserBean userBean){
        userService.zhanggai(userBean);
    }

    //测试
    @RequestMapping("queryList")
    public LayuiPage queryList(Integer page, Integer limit,@RequestBody ZhaoPinBean zhaoPinBean){
        return userService.queryList(page,limit,zhaoPinBean);
    }


    //测试 精确查询
    @RequestMapping("queryType")
    public List<ComUserBean> queryType(){
        List<ComUserBean> comUserBeans = userService.queryType();
        return comUserBeans;
    }

    //查询招聘的岗位
    @RequestMapping("findZhaoPin")
    public List<ZhaoPinBean> findZhaoPin(){
        List<ZhaoPinBean> zhaoPinBeans = userService.findZhaoPin();
        return zhaoPinBeans;
    }

    //修改收藏状态
    @RequestMapping("productState")
    @ResponseBody
    public Boolean productState(Integer id){
        try {
            userService.productState(id);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
    //根据userId 查询具体的数据
    @RequestMapping("findQueryUserList")
    public UserBean findQueryUserList(Integer id){
        UserBean queryUserList = userService.findQueryUserList(id);
        return queryUserList;
    }

    //投递按钮
    @RequestMapping("addtoudi")
    @ResponseBody
    public void addtoudi(Integer comid,Integer userid){
        userService.addtoudi(comid,userid);
    }

    //修改 用户密码
    @RequestMapping("updatePassWord")
    public void updatePassWord(Integer id,String md532){
        userService.updatePassWord(id,md532);
    }

    //教育查询
    @RequestMapping("findJiaoYu")
    public ResultBean findJiaoYu(Integer id){
        return userService.findJiaoYu(id);
    }

    //删除教育经历
    @RequestMapping("delJiaoYu")
    public void delJiaoYu(Integer id){
        userService.delJiaoYu(id);
    }

    //新增教育经历
    @RequestMapping("saveJiaoYu")
    public void saveJiaoYu(@RequestBody JiaoYuBen jiaoYuBen){
        userService.saveJiaoYu(jiaoYuBen);
    }

    /**
     * 查询项目经验
     * @param id
     * @return
     */
    @RequestMapping("JingYanBean")
    @ResponseBody
    public LayuiPage JingYanBean(Integer id){
        return userService.JingYanBean(id);
    }

    /**
     * 新增项目经验
     * @param jingYanBean
     */
    @RequestMapping("addXiangmu")
    @ResponseBody
    public void addXiangmu(@RequestBody JingYanBean jingYanBean){
        userService.addXiangmu(jingYanBean);
    }

    @RequestMapping("delXiangMu")
    @ResponseBody
    public void delXiangMu(Integer id){
        userService.delXiangMu(id);
    }

    //工作经历表
    @RequestMapping("findUserGongZuoJingLi")
    public ResultBean findUserGongZuoJingLi(Integer id){
        System.out.println("工作经历表");
        ResultBean userGongZuoJingLi = userService.findUserGongZuoJingLi(id);
        return userGongZuoJingLi;
    }

    //删除工作经历表
    @RequestMapping("delGongZuo")
    public void delGongZuo(Integer id){
        userService.delGongZuo(id);
    }

    //新增工作经历表
    @RequestMapping("saveGongZuo")
    public void saveGongZuo(@RequestBody GongZuoBean gongZuoBean){
        userService.saveGongZuo(gongZuoBean);
    }


    @RequestMapping("queryjituan")
    @ResponseBody
    public List<Map> queryjituan(Integer comid){

        return userService.queryjituan(comid);
    }


}